package com.zzptc.zzj.a121huatu;

import android.graphics.Color;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;

import java.util.ArrayList;
import java.util.List;


public class SecondFragment extends Fragment {

    public SecondFragment() {
        // Required empty public constructor
    }

    public static SecondFragment newInstance(String param1, String param2) {
        SecondFragment fragment = new SecondFragment();
        Bundle args = new Bundle();

        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_second, container, false);
        BarChart bar=view.findViewById(R.id.barChat);

        List<BarEntry> data=new ArrayList<>();
        data.add(new BarEntry(1,3));
        data.add(new BarEntry(2,6));
        data.add(new BarEntry(3,4));
        data.add(new BarEntry(4,8));
        data.add(new BarEntry(5,7));

        List<BarEntry> data1=new ArrayList<>();
        data1.add(new BarEntry(1,6));
        data1.add(new BarEntry(2,2));
        data1.add(new BarEntry(3,7));
        data1.add(new BarEntry(4,5));
        data1.add(new BarEntry(5,9));
        //放数据
        BarDataSet barDataSet = new BarDataSet(data, "");
        BarDataSet barDataSet1 = new BarDataSet(data1, "");

        barDataSet.setColor(Color.RED);
        barDataSet1.setColor(Color.BLUE);

        BarData barData = new BarData();
        barData.addDataSet(barDataSet);
        barData.addDataSet(barDataSet1);
        //布局中的空间与数据关联
        bar.setData(barData);

        bar.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);//BOTTOM下
        bar.getAxisRight().setEnabled(false);
        bar.getDescription().setEnabled(false);//隐藏英文单词\
        barData.groupBars(1,0.6f,0);
        //barData.setBarWidth(0.2f);

        bar.getXAxis().setAxisMaximum(12);
        bar.getXAxis().setAxisMinimum(1);
        bar.getXAxis().setLabelCount(5,false);
        bar.getXAxis().setCenterAxisLabels(true);

        return view;
    }
}
